﻿package mortal.common
{
    import flash.display.*;
    import flash.events.*;
    import mortal.mvc.core.*;

    public class EventUtil extends Object
    {

        public function EventUtil()
        {
            return;
        }// end function

        public static function addEvent(param1:IEventDispatcher, param2:String, param3:Function, param4:Boolean, param5:Boolean = false, param6:int = 0, param7:Boolean = false) : void
        {
            if (param4)
            {
                param1.addEventListener(param2, param3, param5, param6, param7);
            }
            else
            {
                param1.removeEventListener(param2, param3, param5);
            }
            return;
        }// end function

        public static function addDoubleClick(param1:DisplayObjectContainer, param2:Function, param3:Boolean, param4:Boolean = false, param5:int = 0, param6:Boolean = false) : void
        {
            param1.doubleClickEnabled = param3;
            addEvent(param1, MouseEvent.DOUBLE_CLICK, param2, param3, param4, param5, param6);
            return;
        }// end function

        public static function addNetEvent(param1:String, param2:Function, param3:Boolean, param4:Boolean = false) : void
        {
            if (param3)
            {
                if (param4)
                {
                    if (NetDispatcher.hasCmdListener(param1) == false)
                    {
                        NetDispatcher.addCmdListener(param1, param2);
                    }
                }
                else
                {
                    NetDispatcher.addCmdListener(param1, param2);
                }
            }
            else
            {
                NetDispatcher.removeCmdListener(param1, param2);
            }
            return;
        }// end function

        public static function addSelfEvent(param1:String, param2:Function, param3:Boolean, param4:Boolean = false, param5:Boolean = false, param6:int = 0, param7:Boolean = false) : void
        {
            if (param3)
            {
                if (param4)
                {
                    if (Dispatcher.hasEventListener(param1) == false)
                    {
                        Dispatcher.addEventListener(param1, param2, param5, param6, param7);
                    }
                }
                else
                {
                    Dispatcher.addEventListener(param1, param2, param5, param6, param7);
                }
            }
            else
            {
                Dispatcher.removeEventListener(param1, param2, param5);
            }
            return;
        }// end function

    }
}
